<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
	<div class="container-fluid">
		<div class="navbar-header">
			<div class="brand">易才产品管理系统</div>
			<div class="navTopP pull-right ">
				健康管理主管：<strong> ${user.realName} </strong>您好,欢迎登陆使用！ <br> <strong
					class="mR15"><a href="#" id="openModifyPassword" data-toggle="modal" style="color: #fff;">修改密码</a></strong> <strong><a
					href="${ctx}/admin/logout" style="color: #fff;">安全退出</a> </strong>
			</div>
		</div>
	</div>
</nav>

<div class="modal fade" id="myModifyPasswordModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h4 id="myModalLabel">修改密码</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="userForm">
					<div class="form-group">
		                <label class="control-label text-right col-md-4" >新密码：</label>
		                <div class="col-sm-8">
		               		<input id="newPassword" name="newPassword" type="password" class="form-control">
		                </div>
		            </div>
					<div class="form-group">
		                <label class="control-label text-right col-md-4" >确认新密码：</label>
		                <div class="col-sm-8">
		                	<input id="confirmNewPassword" name="confirmNewPassword" type="password" class="form-control">
		                </div>
		            </div>
				</form>
			</div>
			<div class="modal-footer">
				<button class="btn btn-primary" id="btnSave">保存</button>
				<button class="btn btn-danger" data-dismiss="modal" aria-hidden="true">取消</button>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
$("#openModifyPassword").click(function () {
	$("#newPassword").val("");
	$("#confirmNewPassword").val("");
	$("#myModifyPasswordModal").modal("show");
});

$("#btnSave").click(function () {
 var password = $.trim($("#newPassword").val());
 var confirmPassword = $.trim($("#confirmNewPassword").val());
	if(password=="") {
		alert("请输入新密码");
		return false;
	}	
	if(!passwordCheck(password)) {
		alert("新密码格式错误");
		return false;
	}
	if(confirmPassword=="") {
		alert("请输入确认新密码");
		return false;
	}
	if(!passwordCheck(confirmPassword)) {
		alert("确认新密码格式错误");
		return false;
	}
	if(password!=confirmPassword) {
		alert("输入的新密码和确认新密码不一样");
		return false;
	}
	$.ajax({
	    url: "${ctx}/admin/system/user/modifyPassword",
	    data: {password:password},
	    type: "post",
	    success: function(data) {
	   		alert("修改成功");
	   		$("#myModifyPasswordModal").modal('hide');	   		
	    },
	    error: function (error) {
	        console.log(error);
	    }
	});
});
</script>